/*
 * @Project Name: spring-boot
 * @File Name: TestController
 * @Package Name: com.hhly.spring.boot.cache
 * @Date: 2018/4/18 12:19
 * @Creator: linshixing-1199
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.controller.system;

import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.util.JSONUtil;
import com.sm.shoplook.vo.base.ApiResult;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chenpy-1072
 * @desc SystmePageController
 * @date 2018/4/18 12:19
 * @see
 */
@Controller
public class SystmePageController {

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String login() {
		return "login";
	}

	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index(HttpSession session) {
		return "index";
	}

	@ResponseBody
	@RequestMapping(value = "/initIndex", method = RequestMethod.GET)
	public ApiResult<Map<String, Object>> initIndex() {
        Session shiroSession = SecurityUtils.getSubject().getSession();
        Object principal = SecurityUtils.getSubject().getPrincipal();
        Object permissionCodes = shiroSession.getAttribute("permissionCodes");
        if (principal == null && permissionCodes == null) {
            return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1);
        }
        Map<String, Object> resultMap = new HashMap<>(2);
        resultMap.put("permissionCodes", permissionCodes);
        resultMap.put("sessionUser", JSONUtil.writeValueAsString(principal));
        return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, resultMap);
    }

	@RequestMapping(value = "/addUpdateFind", method = RequestMethod.GET)
	public String add_update_find() {
		return "/service/add_update_find";
	}
	/*
	 * ResponseBody
	 * @RequestMapping(value = "/tableData", method = RequestMethod.POST) public
	 * ApiResult<Map<String, Object>> tableData() { ApiResult<Map<String, Object>>
	 * result = new ApiResult<>(); result.setCode(1); result.setMessage("操作成功");
	 * Map<String, Object> map = new HashMap<>(); List<User> users = new
	 * ArrayList<>(); for (int i = 0; i < 10; i++) { User user = new User();
	 * user.setId((long) (i + 1)); user.setNickname("nickName-" + (i + 1));
	 * user.setEmail("email"+(i + 1)+"@com"); users.add(user); } map.put("rows",
	 * users); map.put("total", 55); result.setData(map); return result; }
	 * @RequestMapping(value = "/add", method = RequestMethod.GET) public String
	 * add() { return "add"; }
	 * @ResponseBody
	 * @RequestMapping("/selectData") public ApiResult<List<User>>
	 * selectData(@RequestParam(value = "searchKey", required = false) String
	 * searchKey) { ApiResult<List<User>> result = new ApiResult<>();
	 * result.setCode(1); result.setMessage("操作成功"); List<User> users = new
	 * ArrayList<>(); for (int i = 0; i < 10; i++) { User user = new User();
	 * user.setId((long) (i + 1)); user.setNickname("nickName-" + (i + 1));
	 * user.setEmail("email"+(i + 1)+"@com"); users.add(user); }
	 * result.setData(users); return result; }
	 */
}
